package com.hx.er.action.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hx.er.bean.base.StatusBean;
import com.hx.er.common.system.Constants;
import com.hx.er.common.system.ErProperties;

public class ErManagerPageAction extends ErManagerAction {

	// 序列化ID
	private static final long serialVersionUID = -9171590900657838753L;
	protected int pageCount;
	protected int pageIndex;
	protected int dataListLimit = Integer.parseInt(ErProperties.getProperty(Constants.PROPERTY_PAGE_SIZE));
	protected String actionPath;
	private List<StatusBean> statusList;
	// 默认是查询全部，如果此处不赋值，则默认为0，会查询出“已删除”的数据
	private long statusId = 9;

	public ErManagerPageAction() {
		// 调用父类构造方法
		super();

		// 初始化页面元素
		this.initPage();

		// 获取页面请求路径
		String[] values = super.servletPath.split("/");
		this.actionPath = values[values.length - 1];
	}

	/**
	 * 使用默认页数的情况下调用
	 * 
	 * @return
	 */
	protected Map<String, Object> getConditionMap() {
		Map<String, Object> conditions = new HashMap<String, Object>();
		int minLimit = this.pageIndex * this.dataListLimit;

		// 检索条目数，翻页用
		conditions.put(Constants.CONDITION_MIN_LIMIT, minLimit);
		conditions.put(Constants.CONDITION_DATA_LIMIT, this.dataListLimit);

		// 检索条件:状态
		conditions.put("statusId", this.statusId);

		return conditions;
	}

	/**
	 * 自定义页数的情况下调用
	 * 
	 * @param dataListLimit
	 * @return
	 */
	protected Map<String, Object> getConditionMap(int dataListLimit) {
		// 给属性赋值，同时此类只要不再初始化，每页数据的值便始终是这个数
		this.dataListLimit = dataListLimit;

		// 返回使用最新值生成的检索条件
		return this.getConditionMap();
	}

	private void initPage() {
		// 初始化检索条件下拉框
		this.statusList = new ArrayList<>();
		StatusBean status0 = new StatusBean();
		status0.setId(0);
		status0.setName(super.getText(Constants.PROPERTY_STATUS_VALUE0));
		StatusBean status1 = new StatusBean();
		status1.setId(1);
		status1.setName(super.getText(Constants.PROPERTY_STATUS_VALUE1));
		StatusBean status9 = new StatusBean();
		status9.setId(9);
		status9.setName(super.getText(Constants.PROPERTY_STATUS_VALUE9));
		this.statusList.add(status9);
		this.statusList.add(status1);
		this.statusList.add(status0);
	}

	public int getPageCount() {
		return this.pageCount;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public String getActionPath() {
		return actionPath;
	}

	public void setActionPath(String actionPath) {
		this.actionPath = actionPath;
	}

	public List<StatusBean> getStatusList() {
		return statusList;
	}

	public void setStatusList(List<StatusBean> statusList) {
		this.statusList = statusList;
	}

	public long getStatusId() {
		return statusId;
	}

	public void setStatusId(long statusId) {
		this.statusId = statusId;
	}
}
